package me.principality.dapp.filter

import org.slf4j.LoggerFactory
import javax.ws.rs.container.ContainerResponseFilter
import kotlin.Throws
import java.io.IOException
import javax.ws.rs.container.ContainerRequestContext
import javax.ws.rs.container.ContainerResponseContext

class CORSFilter : ContainerResponseFilter {
    // Logger
    private val log = LoggerFactory.getLogger(CORSFilter::class.java)
    @Throws(IOException::class)
    override fun filter(
        requestContext: ContainerRequestContext,
        cres: ContainerResponseContext
    ) {
        cres.headers.add("Access-Control-Allow-Origin", "*")
        cres.headers.add(
            "Access-Control-Allow-Headers",
            "accept, origin, authorization, content-type, x-requested-with"
        )
        cres.headers.add("Access-Control-Allow-Methods", "GET,POST,OPTIONS")
        cres.headers.add("Access-Control-Max-Age", "1209600")
    }
}